<template>
	<view>
		<u-sticky>
			<u-tabs :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
		</u-sticky>
		<view v-if="current===0">
			<view class="oneday">
				<u-image width="100%" height="2200rpx" :src="dataobj.image" mode="widthFix"></u-image>
			</view>
			<!-- <u-button type="warning" class="but" @click="baoimg">保存图片</u-button> -->
			<button type="default" class="but">保存图片</button>
		</view>
		<view class="item2" v-else>
			<rich-text :nodes="strings"></rich-text>
			<!-- <u-button type="warning" class="but" @click="copytext">复制内容</u-button> -->
			<button type="default" class="but">复制内容</button>
		</view>
		<view style="width: 100%;height: 20px;">
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataobj: {},
				strings: '',
				list: [{
					name: '图片'
				}, {
					name: '文字'
				}],
				current: 0
			}
		},
		onLoad() {
			this.getdata()
		},
		methods: {
			change(index) {
				this.current = index;
			},
			async getdata() {
				let timestamp = +new Date()
				const db = uniCloud.database()
				let res = await db.collection('mor_news').where({
					date: this.$u.timeFormat(timestamp, 'yyyy-mm-dd')
				}).get({
					getOne: true
				})
				if (res.result.code === 0) {
					console.log(res.result.data);
					this.dataobj = res.result.data
					this.strings = res.result.data.news.join('<br><div><br><hr/><br></div>')
				} else {

				}
			},
			baoimg() {
				let arr = []
				arr.push(this.dataobj.image)
				uni.previewImage({
					current: 0,
					urls: arr,
					success: (res) => {

					}
				})
			},
			copytext() {
				uni.setClipboardData({
					data: this.dataobj.news.join('\n'),
					success: function() {
						console.log('success');
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.oneday {
		width: 95%;
		margin: 22rpx auto;
		border-radius: 41rpx;
		border: 6rpx solid #fff;
		font-weight: bold;
		overflow: hidden;
		box-shadow: -3px 3px 6px #d2d2d2;
	}

	.but {
		width: 45%;
		font-weight: bold;
		margin: 30rpx auto;
		background-color: #ff9900;
		color: #fff;
	}

	.item2 {
		margin: 10rpx 20rpx;
		letter-spacing: 4rpx;
		padding-bottom: 40rpx;
	}
</style>
